from tkinter import *
import socket
import struct
import textwrap
import tkinter.messagebox as messagebox
import sniffer
import sys,time
import tkinter

class Application(Frame):
    # conn = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(3))
    # a = Sniffer(conn)
    textContent = "55555"
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()
        # self.packetMsg = ""
        self.packetMsg = StringVar()
        self.packetMsg.set(self.textContent)
        self.label = Label(master, textvariable=self.packetMsg)
        
        # self.Catchpack()
    def createWidgets(self):
        self.packmessage = Text(self)
        self.packmessage.pack(side=tkinter.LEFT,fill=tkinter.Y)
        self.scroll = tkinter.Scrollbar()
        self.scroll.pack(side=tkinter.RIGHT,fill=tkinter.Y)
        self.scroll.config(command=self.packmessage.yview)
        self.packmessage.config(yscrollcommand=self.scroll.set)
        self.packmessage.pack()
        self.alertButton = Button(self, text='开始抓包', command=self.Catchpack)
        self.alertButton.pack()
        

    def hello(self):
        name = self.nameInput.get() or 'world'
        messagebox.showinfo('Message', 'Hello, %s' % name)
    def Catchpack(self):
        packet = sniffer.a.Catch()
        textvariable = packet
        self.packmessage.insert('end',textvariable)
        self.packetMsg.set(textvariable)
        self.label.after(1,self.Catchpack)
        # print(self.packetMsg.)

app = Application()
# 设置窗口标题:
app.master.title('抓包助手')
app.master.geometry('1200x800') 
# app.label.after(1000,app.Catchpack)
# 主消息循环:
while True:
    app.mainloop()